<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
 *
 * == BEGIN LICENSE ==
 *
 * Licensed under the terms of any of the following licenses at your
 * choice:
 *
 *  - GNU General Public License Version 2 or later (the "GPL")
 *    http://www.gnu.org/licenses/gpl.html
 *
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
 *    http://www.gnu.org/licenses/lgpl.html
 *
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
 *    http://www.mozilla.org/MPL/MPL-1.1.html
 *
 * == END LICENSE ==
 *
 * This page shows all resources available in a folder in the File Browser.
-->
<html>
<head>
	<title>Resources</title>
	<link href="browser.css" type="text/css" rel="stylesheet">
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	<script type="text/javascript" src="js/common.js"></script>
	<script type="text/javascript">

var oListManager = new Object() ;

oListManager.Clear = function()
{
	document.body.innerHTML = '' ;
}

function ProtectPath(path)
{
	path = path.replace( /\\/g, '\\\\') ;
	path = path.replace( /'/g, '\\\'') ;
	return path ;
}

oListManager.GetFolderRowHtml = function(folderName, folderPath) {
    // Build the link to view the folder.
    //	var sLink = '<a href="#" onclick="OpenFolder(\'' + ProtectPath( folderPath ) + '\');return false;">' ;

    //	return '<tr>' +
    //			'<td width="16">' +
    //				sLink +
    //				'<img alt="" src="images/Folder.gif" width="16" height="16" border="0"><\/a>' +
    //			'<\/td><td nowrap colspan="2">&nbsp;' +
    //				sLink +
    //				folderName +
    //				'<\/a>' +
    //		'<\/td><\/tr>' ;
    var sLink = '<a href="#" onclick="OpenFolder(\'' + ProtectPath(folderPath) + '\');return false;"><img alt="" src="images/Folder.gif" width="16" height="16" border="0"> ';

    //    var rLink = '<a href="#" title="Rename Folder" onclick="RenameFolder(\'' + folderName + '\');return false;"><img src="images/rename.gif" width="16" height="16" border="0" alt="重命名" title="重命名"></a>';

    var dLink = '<a href="#" title="Delete Folder" onclick="DeleteFolder(\'' + folderName + '\');return false;"><img src="images/delete.gif" width="16" height="16" border="0" alt="删除" title="删除">';

    //    var ssLink = rLink + dLink;
    var ssLink = dLink;
    return '<tr>' +
   '<td width="16"><\/td><td nowrap> ' +
    sLink +
    folderName +
    '<\/a></td><td align="right" nowrap>' + ssLink +
  '<\/td><\/tr>';

}

oListManager.GetFileRowHtml = function(fileName, fileUrl, fileSize) {
    // Build the link to view the folder.
    //	var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath( fileUrl ) + '\');return false;">' ;

    //	// Get the file icon.
    //	var sIcon = oIcons.GetIcon( fileName ) ;

    //	return '<tr>' +
    //			'<td width="16">' +
    //				sLink +
    //				'<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"><\/a>' +
    //			'<\/td><td>&nbsp;' +
    //				sLink +
    //				fileName +
    //				'<\/a>' +
    //			'<\/td><td align="right" nowrap>&nbsp;' +
    //				fileSize +
    //				' KB' +
    //		'<\/td><\/tr>' ;
    var sIcon = oIcons.GetIcon(fileName);

    // Build the link to view the file.
    var sLink = '<a href="#" onclick="OpenFile(\'' + ProtectPath(fileUrl) + '\');return false;"><img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"> ';

    var vLink = '<a href="' + ProtectPath(fileUrl) + '" target="_blank"" title="View file"><img src="images/view.gif" width="16" height="16" border="0" alt="浏览" title="浏览"></a>';

    //    var rLink = '<a href="#" title="Rename file" onclick="RenameFile(\'' + fileName + '\');return false;"><img src="images/rename.gif" width="16" height="16" border="0" alt="重命名" title="重命名"></a>';

    var dLink = '<a href="#" title="Delete file" onclick="DeleteFile(\'' + fileName + '\');return false;"><img src="images/delete.gif" width="16" height="16" border="0" alt="删除" title="删除"></a>';


    // Get the file icon.
    //    var ssLink = vLink + rLink + dLink;
    var ssLink = vLink + dLink;
    return '<tr>' +
   '<td width="16"><\/td><td> ' +
    sLink +
    fileName +
    '<\/a>' +
   '<\/td><td align="right" nowrap> ' +
    fileSize +
    ' KB' + ssLink +
  '<\/td><\/tr>';

}

function OpenFolder( folderPath )
{
	// Load the resources list for this folder.
	window.parent.frames['frmFolders'].LoadFolders( folderPath ) ;
}

function OpenFile( fileUrl )
{
	window.top.opener.SetUrl( encodeURI( fileUrl ).replace( '#', '%23' ) ) ;
	window.top.close() ;
	window.top.opener.focus() ;
}

//新增部分
function DeleteFolder(folderUrl) {
    if (!confirm('Do you really delete the folder "' + folderUrl + '" ?')) return false;

    oConnector.SendCommand('DeleteFolder', 'FolderName=' + (encodeURI(folderUrl)), DeleteFolderCallBack);
}

function DeleteFolderCallBack(fckXml) {
    var oNode = fckXml.SelectSingleNode('Connector/Error');
    var iErrorNumber = parseInt(oNode.attributes.getNamedItem('number').value);
    var sErrorDescription = String(oNode.attributes.getNamedItem('text').value);

    switch (iErrorNumber) {
        case 0:
            Refresh();
            break;
        case 201:
            alert('You have no permissions to delete the folder');
            break;
        case 202:
            alert('Invalid folder name' + sErrorDescription);
            break;
        case 203:
            alert('Folder not exists' + sErrorDescription);
            break;
        default:
            alert('Error deleting folder. \nError number: ' + iErrorNumber + ' \nError description: ' + sErrorDescription);
            break;
    }
}

function DeleteFile(fileUrl) {
    if (!confirm('Do you really delete the file "' + fileUrl + '" ?')) return false;

    oConnector.SendCommand('DeleteFile', 'FileName=' + encodeURI(fileUrl), DeleteFileCallBack);
}

function DeleteFileCallBack(fckXml) {
    var oNode = fckXml.SelectSingleNode('Connector/Error');
    var iErrorNumber = parseInt(oNode.attributes.getNamedItem('number').value);
    var sErrorDescription = String(oNode.attributes.getNamedItem('text').value);

    switch (iErrorNumber) {
        case 0:
            Refresh();
            break;
        case 301:
            alert('You have no permissions to delete the file');
            break;
        case 302:
            alert('Invalid file name' + sErrorDescription);
            break;
        case 303:
            alert('File not exists' + sErrorDescription);
            break;
        default:
            alert('Error deleting file. \nError number: ' + iErrorNumber + ' \nError description: ' + sErrorDescription);
            break;
    }
}

function RenameFolder(folderName) {
    var newName = prompt('Please enter the new folder name for "' + folderName + '":', folderName);

    if ((newName != null) && (newName != '') && (newName != folderName)) {
        oConnector.SendCommand('RenameFolder', "FolderName=" + encodeURI(folderName) + "&NewName=" + encodeURI(newName), RenameFolderCallBack);
    }
}

function RenameFolderCallBack(fckXml) {
    var oNode = fckXml.SelectSingleNode('Connector/Error');
    var iErrorNumber = parseInt(oNode.attributes.getNamedItem('number').value);
    var sErrorDescription = String(oNode.attributes.getNamedItem('text').value);

    switch (iErrorNumber) {
        case 0:
            Refresh();
            break;
        case 401:
            alert('You have no permissions to rename the folder');
            break;
        case 402:
            alert('Invalid folder name' + sErrorDescription);
            break;
        case 403:
            alert('is not Folder' + sErrorDescription);
            break;
        case 404:
            alert('Folder not exists' + sErrorDescription);
            break;
        default:
            alert('Error renaming folder. \nError number: ' + iErrorNumber + ' \nError description: ' + sErrorDescription);
            break;
    }
}

function RenameFile(fileName) {
    var newName = prompt('Please enter the new file name for "' + fileName + '":', fileName);

    if ((newName != null) && (newName != '') && (newName != fileName)) {
        oConnector.SendCommand('RenameFile', "FileName=" + encodeURI(fileName) + "&NewName=" + encodeURI(newName), RenameFileCallBack);
    }
}

function RenameFileCallBack(fckXml) {
    var oNode = fckXml.SelectSingleNode('Connector/Error');
    var iErrorNumber = parseInt(oNode.attributes.getNamedItem('number').value);
    var sErrorDescription = String(oNode.attributes.getNamedItem('text').value);

    switch (iErrorNumber) {
        case 0:
            Refresh();
            break;
        case 501:
            alert('You have no permissions to rename the file');
            break;
        case 502:
            alert('Invalid file name' + sErrorDescription);
            break;
        case 503:
            alert(sErrorDescription + 'is not a file');
            break;
        case 504:
            alert('File not exists' + sErrorDescription);
            break;
        default:
            alert('Error renaming file. \nError number: ' + ' \nError description: ' + sErrorDescription);
            break;
    }
}

//新增结束

function LoadResources( resourceType, folderPath )
{
	oListManager.Clear() ;
	oConnector.ResourceType = resourceType ;
	oConnector.CurrentFolder = folderPath ;
	oConnector.SendCommand( 'GetFoldersAndFiles', null, GetFoldersAndFilesCallBack ) ;
}

function Refresh()
{
	LoadResources( oConnector.ResourceType, oConnector.CurrentFolder ) ;
}

function GetFoldersAndFilesCallBack( fckXml )
{
	if ( oConnector.CheckError( fckXml ) != 0 )
		return ;

	// Get the current folder path.
	var oFolderNode = fckXml.SelectSingleNode( 'Connector/CurrentFolder' ) ;
	if ( oFolderNode == null )
	{
		alert( 'The server didn\'t reply with a proper XML data. Please check your configuration.' ) ;
		return ;
	}
	var sCurrentFolderPath	= oFolderNode.attributes.getNamedItem('path').value ;
	var sCurrentFolderUrl	= oFolderNode.attributes.getNamedItem('url').value ;

//	var dTimer = new Date() ;

	var oHtml = new StringBuilder( '<table id="tableFiles" cellspacing="1" cellpadding="0" width="100%" border="0">' ) ;

	// Add the Folders.
	var oNodes ;
	oNodes = fckXml.SelectNodes( 'Connector/Folders/Folder' ) ;
	for ( var i = 0 ; i < oNodes.length ; i++ )
	{
		var sFolderName = oNodes[i].attributes.getNamedItem('name').value ;
		oHtml.Append( oListManager.GetFolderRowHtml( sFolderName, sCurrentFolderPath + sFolderName + "/" ) ) ;
	}

	// Add the Files.
	oNodes = fckXml.SelectNodes( 'Connector/Files/File' ) ;
	for ( var j = 0 ; j < oNodes.length ; j++ )
	{
		var oNode = oNodes[j] ;
		var sFileName = oNode.attributes.getNamedItem('name').value ;
		var sFileSize = oNode.attributes.getNamedItem('size').value ;

		// Get the optional "url" attribute. If not available, build the url.
		var oFileUrlAtt = oNodes[j].attributes.getNamedItem('url') ;
		var sFileUrl = oFileUrlAtt != null ? oFileUrlAtt.value : sCurrentFolderUrl + sFileName ;

		oHtml.Append( oListManager.GetFileRowHtml( sFileName, sFileUrl, sFileSize ) ) ;
	}

	oHtml.Append( '<\/table>' ) ;

	document.body.innerHTML = oHtml.ToString() ;

//	window.top.document.title = 'Finished processing in ' + ( ( ( new Date() ) - dTimer ) / 1000 ) + ' seconds' ;

}

window.onload = function()
{
	window.top.IsLoadedResourcesList = true ;
}
	</script>
</head>
<body class="FileArea">
</body>
</html>
